package com.lantosec.hmrp.modules.eval.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lantosec.hmrp.core.config.InitDataListener;
import com.lantosec.hmrp.core.kit.PageVO;
import com.lantosec.hmrp.modules.eval.entity.EvalDetailed;
import com.lantosec.hmrp.modules.eval.mapper.EvalDetailedMapper;
import com.lantosec.hmrp.modules.eval.service.IEvalDetailedService;
import com.lantosec.hmrp.modules.eval.vo.EvalDetailedVO;
import com.lantosec.hmrp.modules.uploads.entity.SysUploads;
import com.lantosec.hmrp.modules.uploads.service.ISysUploadsService;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 考评明细 服务实现类
 * </p>
 *
 * @author AutoCode
 * @since 2020-03-30
 */
@Service
@Primary
@Log4j2
public class EvalDetailedServiceImpl extends ServiceImpl<EvalDetailedMapper, EvalDetailed> implements IEvalDetailedService {
    @Autowired
    private ISysUploadsService iSysUploadsService;

    @Override
    public EvalDetailedVO get(String evalDetailedId) {
        EvalDetailed evalDetailed = this.getOne(new QueryWrapper<EvalDetailed>().eq(EvalDetailed.ColName.eval_detailed_id.toString(),evalDetailedId));
        EvalDetailedVO evalDetailedVO = evalDetailed.convertToVO();
        String evalStartPhoto = evalDetailedVO.getEvalStartPhoto();
        if(StringUtils.isNotEmpty(evalStartPhoto)){
            SysUploads sysUploads = iSysUploadsService.getById(evalStartPhoto);
            String savePath = sysUploads.getSavePath();
            String fileName = sysUploads.getFileName();
            evalDetailedVO.setSavePath(InitDataListener.uploadsUrl + savePath + fileName);
        }
        return evalDetailedVO;
    }

    @Override
    public PageVO<EvalDetailedVO> getEvalDetail(PageVO<EvalDetailedVO> page) {
        PageVO<EvalDetailedVO> evalDetailedVOPageVO = baseMapper.getEvalDetail(page);
        return evalDetailedVOPageVO;
    }
}
